#include "AbstractThreshold.h"



AbstractThreshold::AbstractThreshold () : __thresholdValue (128)
{

}



Ptr< QImage > AbstractThreshold::process (Ptr< QImage > pProcessImage)
{
  Ptr< QImage > pResultImage = new QImage (pProcessImage->size (), 
          QImage::Format_ARGB32);
  for (int v = 0; v < pProcessImage->height (); ++v)
  {
    QRgb * srcLine = (QRgb *)pProcessImage->constScanLine (v);
    QRgb * resultLine = (QRgb *)pResultImage->scanLine (v);
    for (int u = 0; u < pProcessImage->width (); ++u)
      if (qGray (srcLine[u]) >= __thresholdValue)
        resultLine[u] = qRgba (255, 255, 255, qAlpha (srcLine[u]));
      else
        resultLine[u] = qRgba (0, 0, 0, qAlpha (srcLine[u]));
  }
  return pResultImage;
}

int AbstractThreshold::getThresholdValue () const
{
  return __thresholdValue;
}
